#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;

typedef struct room
{
    int atmostcanbuy;
    int total_price;
    double value;
} Room;

bool cmp(Room A, Room B)
{
    return A.value < B.value;
}

int main()
{
    ios::sync_with_stdio(false);
    Room mi[1001];
    int M, N;
    int i;
    int testcases;
    double result = 0.0;
    cin >> testcases;
    while (testcases--)
    {
        cin >> M >> N;
        result = 0;
        for (i = 0; i < N; i++)
        {
            cin >> mi[i].value >> mi[i].atmostcanbuy;
            mi[i].total_price = mi[i].value * mi[i].atmostcanbuy;
        }
        sort(mi, mi + N, cmp);
        for (i = 0; i < N; i++)
        {
            if (M > mi[i].total_price)
            {
                result += mi[i].atmostcanbuy;
                M -= mi[i].total_price;
            }
            else
            {
                result += M / mi[i].value * 1.0;
                break;
            }
        }
        cout << fixed << setprecision(2) << result << endl;
    }
}